/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (almaslvl@gmail.com).
 * See LICENSE for details.
 */

package com.windea.study.kotlin.fxgl.sample.sandbox

import com.almasb.fxgl.animation.*
import com.almasb.fxgl.app.*
import com.almasb.fxgl.dsl.*
import com.windea.study.kotlin.fxgl.sample.dev.*
import dev.*
import javafx.scene.input.*
import javafx.scene.paint.*
import javafx.scene.shape.*


/**
 * Shows how to use input service and bind actions to triggers.
 */
class InputSample3 : GameApplication() {
	//FIXME NPE
	private lateinit var a: Animation<*>
	
	override fun initSettings(settings: GameSettings) {
		settings.width = 800
		settings.height = 600
		settings.title = "InputSample3"
		settings.version = "0.1"
	}
	
	override fun initInput() {
		onKeyDown(KeyCode.Q, "Shake") { getGameScene().viewport.shake(5.0, 0.0) }
		
		onKeyDown(KeyCode.E, "Lazy") { getGameScene().viewport.isLazy = !getGameScene().viewport.isLazy }
		
		onKeyDown(KeyCode.F, "Flash") { getGameScene().viewport.flash(Runnable { println("Flash finished") }) }
		
		onKeyDown(KeyCode.G, "Fade") { getGameScene().viewport.fade(Runnable { println("Fade finished") }) }
	}
	
	override fun initGame() {
		entityBuilder()
			.view("background.png")
			.buildAndAttach()
		
		val e = entityBuilder()
			.at(150.0, 150.0)
			.view(Rectangle(10.0, 10.0, Color.BLUE))
			.with(DeveloperWASDControl())
			.buildAndAttach()
		
		getGameScene().viewport.setBounds(30, 30, 1600 - 30, 1200 - 30)
		getGameScene().viewport.bindToEntity(e, (getAppWidth() / 2).toDouble(), (getAppHeight() / 2).toDouble())
		
		//a =  translateAnim(getGameScene().getViewport().getCamera(), new Point2D(0, 0), new Point2D(400, 400), Duration.ZERO, Duration.seconds(1.5), () -> {}, Interpolators.EXPONENTIAL.EASE_OUT());
		
		a.isAutoReverse = true
		a.cycleCount = 2
	}
	
	public override fun onUpdate(tpf: Double) {
		a.onUpdate(tpf)
	}
}


fun main(args: Array<String>) {
	GameApplication.launch(InputSample3::class.java, args)
}

